<template>
	<view class="wid100">
		<view v-if="list" class="wid90 mar">
			<view class="hei20"></view>
			<view class="borRad40 dis disAl disJuC foSi25 hei60 coFFF mar foSi28" @click="fanhui"
				style="background: linear-gradient(to right, #fb8480, #fa3f86);width: 240rpx;">返回首页</view>
			<view class="hei20"></view>
			<view class="dis disAl hei60">
				<image :src="image" style="width: 60rpx;" class="hei100 mar-right30 borRad50"></image>
				<view class="foSi28" style="color: #888;">{{name}}</view>
			</view>
			<view class="mar-top40">
				<view class="hei20"></view>
				<view class="mar" style="width: 120rpx;height: 120rpx;">
					<image v-if="system == 'Android'" src="../../static/android.png" class="wh100"></image>
					<image v-if="system == 'ios'" src="../../static/ios.png" class="wh100"></image>
				</view>
				<view class="textCen foSi30 mar-top20">{{list.sub_name}}{{system=='ios'?'.ipa':'.apk'}}</view>
				<view class="mar-top20 foSi25 textCen" style="color: #888;">{{system}}</view>
				<view class="wid100 dis disJuC mar-top40">
					<view class="dis disAl disJuC foSi30 coFFF borRad20 hei86"
						style="padding: 0 30rpx;background-color: #86d2ff;" @click="xiazai()">下载文件</view>
				</view>
				<view class="jingshi foSi18 wid100 mar-top20 textCen">谨防刷单兼职，网贷，金融，裸聊敲诈，赌博等诈骗，请立即举报</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				system: 'Android',
				list: null,
				name: '',
				image: ''
			}
		},
		onLoad(options) {
			this.id = options.id
			this.name = options.name
			this.image = options.image
			if (uni.getSystemInfoSync().platform == 'ios') {
				this.system = 'ios'
			}
			this.getList()
		},
		methods: {
			fanhui(){
				uni.navigateBack(1)
			},
			xiazai() {

				var filePath = this.list.android_package;
				if (this.system == 'ios') {
					filePath = this.list.ios_package
				}
				if (filePath) {
					const tempLink = document.createElement("a");
					tempLink.style.display = "none";
					tempLink.href = filePath;
					tempLink.setAttribute("download", this.list.sub_name);
					tempLink.setAttribute("target", "_blank");
					document.body.appendChild(tempLink);
					tempLink.click();
					document.body.removeChild(tempLink);
				} else {
					uni.showModal({
						title: '提示',
						content: '文件已失效，请联系管理员?',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								// 执行确认后的操作
							} else {
								// 执行取消后的操作
							}
						}
					})
				}

			},
			getList() {
				var that = this
				uni.request({
					url: this.global.url + 'api/zy/article_detail',
					method: 'POST',
					data: {
						id: that.id
					},
					success: (res) => {
						let result = res.data
						if (result.code == 1) {
							that.list = result.data
							uni.setNavigationBarTitle({
								title: result.data.name
							});
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'error'
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				});
			},
		}
	}
</script>

<style>
	.richImg {
		width: 100% !important;
		height: auto !important;
	}

	.jingshi {
		color: #8a6d3b;
		background-color: #fcf8e3;
		padding: 5px 10px;
		border-radius: 6px;
	}
</style>